package com.q.tqb.activity;

import android.graphics.Bitmap;
import android.os.Vibrator;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.WindowManager;
import android.widget.TextView;

import com.q.tqb.R;
import com.q.tqb.adapter.ImagePagerAdapter;
import com.q.tqb.base.BaseActivity;
import com.q.tqb.util.StatusBarUtil;
import com.q.tqb.view.popwindow.ImagePopWindow;

public class ViewPagerImageActivity extends BaseActivity {


    private TextView mTextView;
    private int size;


    @Override
    public int getLayoutId() {
        return R.layout.activity_view_pager_image;
    }

    @Override
    public void init(Bundle savedInstanceState) {

        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); //隐藏状态栏
        ViewPager viewPager = findViewById(R.id.view_pager);
        mTextView = findViewById(R.id.tv_index);
        String[] images = getIntent().getStringArrayExtra("images");
        int position = getIntent().getIntExtra("position", 0);
        size = images.length;
        ImagePagerAdapter imagePagerAdapter = new ImagePagerAdapter(this, images);
        viewPager.setAdapter(imagePagerAdapter);
        imagePagerAdapter.setOnItemClickListener(new ImagePagerAdapter.OnLongClickListener() {
            @Override
            public void onLongClick(Bitmap mBitmap) {
                Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
                vibrator.vibrate(30);
                ImagePopWindow imagePopWindow = new ImagePopWindow(ViewPagerImageActivity.this, mBitmap);
                imagePopWindow.showAtLocation(findViewById(R.id.rl_main), Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
            }
        });


        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            }

            @Override
            public void onPageSelected(int position) {
                mTextView.setText((position + 1) + " / " + size);
            }

            @Override
            public void onPageScrollStateChanged(int state) {
            }
        });
        mTextView.setText((position + 1) + " / " + size);
        viewPager.setCurrentItem(position);
    }
}
